﻿using System.Linq;
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.Interfaces;

namespace iss.sg4210.se18.team6s.jass.DAL.DataAccess.MSSQL
{
    public class AlertCriteriaDAO : ObjectDAO, IAlertCriteria
    {
        public IQueryable<AlertCriteria> FindAllAlertCriterias()
        {
            return jassEntities.AlertCriterias;
        }

        public AlertCriteria GetAlertCriteria(int alertCriteriaId)
        {
            return jassEntities.AlertCriterias.SingleOrDefault<AlertCriteria>(m => m.Id == alertCriteriaId);
        }

        public void AddAlertCriteria(AlertCriteria alertCriteria)
        {
            jassEntities.AddToAlertCriterias(alertCriteria);
            Save();
        }

        public void UpdateAlertCriteria(AlertCriteria alertCriteria)
        {
            jassEntities.AlertCriterias.ApplyCurrentValues(alertCriteria);
            Save();
        }

        public void DeleteAlertCriteria(int alertCriteriaId)
        {
            AlertCriteria alertCriteria = GetAlertCriteria(alertCriteriaId);
            jassEntities.AlertCriterias.DeleteObject(alertCriteria);
            Save();
        }


        public IQueryable<AlertCriteria> FindAllAlertCriteriasByUser(System.Guid userId)
        {
            return jassEntities.AlertCriterias.Where<AlertCriteria>(m => m.UserId == userId);
        }
    }
}
